package com.sj.server;

import com.sj.common.lang.NormalConst;
import com.sj.command.Command;
import com.sj.pojo.FirstProtocol;
import com.sj.pojo.MsgTypeEnum;
import com.sj.pojo.Protocol;

import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: xiaoqi
 * Date: 2022-07-08
 * Time: 上午 11:10
 * Description: 正常指令
 *
 * @author xiaoqi
 * @since 2022-07-08
 */
public class NormalInstruct {

    private NormalInstruct() {

    }

    public static Protocol operationInstruct(String msg) {
        FirstProtocol firstProtocol = new FirstProtocol();
        String[] instruct = msg.split(" ");
        if (NormalConst.KEYS.equalsIgnoreCase(instruct[0])) {
            if (instruct.length == 2 && NormalConst.ASTER_RISK.equalsIgnoreCase(instruct[1])) {
                StringBuilder res = new StringBuilder("");
                Set<String> keys = Command.dict.keySet();
                System.out.println(keys);
                for (String name : keys) {
                    res.append(name);
                    res.append(",");
                }
                if (res.length() > 0) {
                    String resultMsg = res.substring(0, res.length() - 1);

                    return firstProtocol.getProtocol(MsgTypeEnum.RESPONSE, resultMsg);
                }
            }
            return firstProtocol.getProtocol(MsgTypeEnum.RESPONSE, "错误的命令!");
        }
        return null;
    }


}